package com.tensquare.rabbit.test;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by DUZEYU on 2018/12/23.
 */
public class OracleTime {
    /**
     * 获取数据库时间类型 yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static Timestamp getTimestamp(){
        Timestamp timestamp = null;
        try {
            timestamp = new Timestamp(System.currentTimeMillis());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return timestamp;
    }
    /**
     * 获取数据库时间类型 yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static Timestamp getTimestamp(Date date){
        Timestamp timestamp = null;
        try {
            timestamp = new Timestamp(date.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return timestamp;
    }
    /**
     * 获取数据库时间类型 yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static String getDate(Date date,String formatType){
        String format = null;
        try {
            format = new SimpleDateFormat(formatType).format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return format;
    }
    /**
     * 获取数据库时间类型 formatType
     * @return
     */
    public static Date getDate(String date,String formatType){
        try {
            Date parse = new SimpleDateFormat(formatType).parse(date);
            return parse;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 获取数据库时间类型 formatType
     * @return
     */
    public static Date getDate(){
        try {
            Date date = new Date();
            return date;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
